package com.jielin.handling.controller.record;

import com.alibaba.fastjson.JSONObject;
import com.jielin.handling.Annotation.MyPower;
import com.jielin.handling.bean.AppResult;
import com.jielin.handling.entity.record.*;
import com.jielin.handling.entity.vo.record.First;
import com.jielin.handling.entity.vo.record.RecordApplyParams;
import com.jielin.handling.entity.vo.record.Two;
import com.jielin.handling.exception.ResultEnum;
import com.jielin.handling.service.record.*;
import com.jielin.handling.util.ConstantUtil;
import com.jielin.handling.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List;

/**
 * @author WR 笔录模块
 */
@CrossOrigin
@Controller
@RequestMapping("/record")
@Slf4j
@Validated
@MyPower(name = "笔录模块", url = "/record")
public class RecordController {
    @Autowired
    private RecordTypeModelService recordTypeModelService;
    @Autowired
    private RecordNoticeService recordNoticeService;
    @Autowired
    private RecordDetailedService recordDetailedService;
    @Autowired
    private RecordCommonalityModelService recordCommonalityModelService;
    @Autowired
    private RecordQuestionService recordQuestionService;
    @Autowired
    private RecordAnswerService recordAnswerService;
    @Autowired
    private RecordStopService recordStopService;
    @Autowired
    private RecordApplyService recordApplyService;

    /**
     * 获取地图数据
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/findMapInfo")
    public AppResult findMapInfo() {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        log.info("..........findMapInfo");
        String map = recordTypeModelService.findMapInfo();
        log.info("list:{}", JSONObject.toJSONString(map));

        data.put("value", map);
        result.setCode(200);
        result.setMsg("查询成功！");
        result.setData(data);
        return result;
    }

    /**
     * 查询所有笔录类型模板
     *
     * @param orgId    单位id
     * @param policeId 警员id
     * @return
     */
    @ResponseBody
    @MyPower(name = "查询所有笔录类型模板", url = "/findAllModel")
    @RequestMapping(value = "/findAllModel")
    public AppResult findAllModel(String orgId, String policeId) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        List<RecordTypeModel> list = recordTypeModelService.findAllModel(orgId, policeId);

        data.put("value", list);
        result.setCode(200);
        result.setMsg("查询成功！");
        result.setData(data);
        return result;
    }

    /**
     * 根据笔录类型id查询所有笔录模板信息
     *
     * @param modeltypeid 模板类型
     * @param policeId    警员id
     * @return
     */
    @ResponseBody
    @MyPower(name = "根据笔录类型id查询所有笔录模板信息", url = "/findCommonalityByModelId")
    @RequestMapping(value = "/findCommonalityByModelId")
    public AppResult findCommonalityByModelId(String modeltypeid, String policeId) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        if (StringUtil.isEmpty(modeltypeid)) {
            data.put("value", -1);
            result.setCode(-1);
            result.setMsg("请选择笔录模板！");
            result.setData(data);
            return result;
        }
        log.info("..........findCommonalityByModelId");
        List<RecordCommonalityModel> list = recordCommonalityModelService.findCommonalityByModelId(modeltypeid,
                policeId);
        log.info("list:{}", JSONObject.toJSONString(list));

        data.put("value", list);
        result.setCode(200);
        result.setMsg("查询成功！");
        result.setData(data);
        return result;
    }

    /**
     * 查询所有的告知书信息
     *
     * @return
     */
    @ResponseBody
    @MyPower(name = "查询所有的告知书信息", url = "/findAllNotice")
    @RequestMapping(value = "/findAllNotice")
    public AppResult findAllNotice() {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        log.info("..........findAllNotice");
        List<RecordNotice> list = recordNoticeService.findAllNotice();
        log.info("list:{}", JSONObject.toJSONString(list));

        data.put("value", list);
        result.setCode(200);
        result.setMsg("查询成功！");
        result.setData(data);
        return result;
    }

    /**
     * 查询所有笔录信息
     *
     * @return
     */
    @ResponseBody
    @MyPower(name = "查询所有笔录信息", url = "/findAllDetailed")
    @RequestMapping(value = "/findAllDetailed")
    public AppResult findAllDetailed() {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        log.info("..........findAllDetailed");
        List<RecordDetailed> list = recordDetailedService.findAllDetailed();
        log.info("list:{}", JSONObject.toJSONString(list));
        data.put("value", list);
        result.setCode(200);
        result.setMsg("查询成功！");
        result.setData(data);
        return result;
    }

    /**
     * 根据笔录id查询笔录详细信息
     *
     * @param detailedId 笔录id
     * @return
     */
    @ResponseBody
    @MyPower(name = "根据笔录id查询笔录详细信息", url = "/findDetailedById")
    @RequestMapping(value = "/findDetailedById")
    public AppResult findDetailedById(@RequestParam("detailedId") String detailedId) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        log.info("..........findAllDetailed");
        RecordDetailed detailed = new RecordDetailed();
        detailed = recordDetailedService.findDetailedById(detailedId);
        log.info("RecordDetailed:{}", JSONObject.toJSONString(detailed));
        data.put("value", detailed);
        result.setCode(200);
        result.setMsg("查询成功！");
        result.setData(data);
        return result;
    }

    /**
     * 根据嫌疑人id(查出以前笔录信息：证件号码)查询对应的笔录所有详细信息
     *
     * @param suspectId 嫌疑人id
     * @param cordId    嫌疑人证件号码
     * @return
     */
    @ResponseBody
    @MyPower(name = "根据嫌疑人id查询对应的笔录所有详细信息", url = "/findDetailedBysuspectId")
    @RequestMapping(value = "/findDetailedBysuspectId")
    public AppResult findDetailedBySuspectId(String suspectId, String cordId) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        log.info("..........findAllDetailed");
        List<RecordDetailed> list = recordDetailedService.findDetailedBySuspectId(suspectId, cordId);
        log.info("list:{}", JSONObject.toJSONString(list));
        data.put("value", list);
        result.setCode(200);
        result.setMsg("查询成功！");
        result.setData(data);
        return result;
    }

    /**
     * 根据笔录模板类型id查询笔录模板的问题信息
     *
     * @param modelid 模板类型ID
     * @return
     */
    @ResponseBody
    @MyPower(name = "根据笔录模板类型id查询笔录模板的问题信息", url = "/findQuestionByModelId")
    @RequestMapping(value = "/findQuestionByModelId")
    public AppResult findQuestionByModelId(String modelid) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        log.info("..........findQuestionByModelId");
        List<RecordQuestion> list = recordQuestionService.findQuestionByModelId(modelid);
        log.info("list:{}", JSONObject.toJSONString(list));

        data.put("value", list);
        result.setCode(200);
        result.setMsg("查询成功！");
        result.setData(data);
        return result;
    }

    /**
     * 根据笔录模板问题id查询笔录模板的答案信息
     *
     * @param questionid 问题id
     * @return
     */
    @ResponseBody
    @MyPower(name = "根据笔录模板问题id查询笔录模板的答案信息", url = "/findAnswerByQuestionId")
    @RequestMapping(value = "/findAnswerByQuestionId")
    public AppResult findAnswerByQuestionId(@RequestParam(value = "questionid", defaultValue = "1") String questionid) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        log.info("..........findQuestionByModelId");
        List<RecordAnswer> list = recordAnswerService.findAnswerByQuestionId(questionid);
        log.info("list:{}", JSONObject.toJSONString(list));

        data.put("value", list);
        result.setCode(200);
        result.setMsg("查询成功！");
        result.setData(data);
        return result;
    }

    /**
     * 初始化一条笔录信息
     *
     * @param recordDetailed
     * @param request
     * @return
     */
    @ResponseBody
    @MyPower(name = "初始化一条笔录信息", url = "/addDetailed")
    @RequestMapping(value = "/addDetailed")
    public AppResult addDetailed(@RequestBody RecordDetailed recordDetailed, HttpServletRequest request) {
        // 设置UUID
        recordDetailed.setId(StringUtil.generatorUUID());
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        log.info("..........addDetailed");
        recordDetailedService.addDetailed(recordDetailed, request.getRemoteAddr());
        data.put("value", recordDetailed.getId());

        result.setCode(200);
        result.setMsg("添加成功！");
        result.setData(data);
        return result;
    }

    /**
     * 保存更新一条笔录信息
     *
     * @param recordDetailed
     * @return
     */
    @ResponseBody
    @MyPower(name = "保存更新一条笔录信息", url = "/updateDetailed")
    @RequestMapping(value = "/updateDetailed")
    public AppResult updateDetailed(@RequestBody RecordDetailed recordDetailed) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        // recordDetailed.setContent("奥术大师多撒多");
        // recordDetailed.setStatus(true);
        log.info("..........updateDetailed");
        data.put("value", recordDetailedService.updateDetailed(recordDetailed));

        result.setCode(200);
        result.setMsg("保存成功！");
        result.setData(data);
        return result;
    }

    /**
     * 初始化新增一条笔录暂停信息
     *
     * @param reStop
     * @return
     */
    @ResponseBody
    @MyPower(name = "初始化新增一条笔录暂停信息", url = "/addStop")
    @RequestMapping(value = "/addStop")
    public AppResult addStop(@RequestBody RecordStop reStop) {
        // 设置UUID
        reStop.setId(StringUtil.generatorUUID());
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        log.info("RecordStop:{}", JSONObject.toJSONString(reStop));
        log.info("..........addStop");
        recordStopService.addStop(reStop);
        data.put("recordStopid", reStop.getId());

        result.setCode(200);
        result.setMsg("添加成功！");
        result.setData(data);
        return result;
    }

    /**
     * 保存更新一条笔录暂停信息
     *
     * @param reStopid 暂停id
     * @return
     */
    @ResponseBody
    @MyPower(name = "保存更新一条笔录暂停信息", url = "/updateStop")
    @RequestMapping(value = "/updateStop")
    public AppResult updateStop(String reStopid) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        log.info("reStopid:{}", JSONObject.toJSONString(reStopid));
        log.info("..........updateDetailed");
        data.put("value", recordStopService.updateStop(reStopid));

        result.setCode(200);
        result.setMsg("保存成功！");
        result.setData(data);
        return result;
    }

    /**
     * 根据笔录详细记录id查询当次笔录的所有暂停信息
     *
     * @param recorddetailedid 笔录详细的id
     * @return
     */
    @ResponseBody
    @MyPower(name = "根据笔录详细记录id查询当次笔录的所有暂停信息", url = "/findAllStopByRecordDetailedId")
    @RequestMapping(value = "/findAllStopByRecordDetailedId")
    public AppResult findAllStopByRecordDetailedId(String recorddetailedid) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        log.info("..........findQuestionByModelId");
        List<RecordStop> list = recordStopService.findAllStopByRecordDetailedId(recorddetailedid);

        log.info("list:{}", JSONObject.toJSONString(list));

        data.put("value", list);
        result.setCode(200);
        result.setMsg("查询成功！");
        result.setData(data);
        return result;
    }

    /**
     * 打印笔录内容
     *
     * @param response
     * @param detailedId 笔录id
     * @param suspectId  嫌疑人id
     * @param watermark  水印内容
     * @param askunit    询/讯问人的工作单位名称
     * @param recordunit 记录人的工作单位名称
     * @param fileString base64字符串签字指纹信息
     * @return
     */
    @ResponseBody
    @MyPower(name = "打印笔录内容", url = "/printDetailed")
    @RequestMapping(value = "/printDetailed")
    public AppResult printDetailed(HttpServletResponse response, @RequestBody @Valid RecordDetailedVo rdv) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        log.info("..........printDetailed");
        // 生成pdf文件的路径
        String path = null;
        String detailedId = rdv.getDetailedId();
        String suspectId = rdv.getSuspectId();
        String watermark = rdv.getWatermark();
        String number = rdv.getNumber();
        String askunit = rdv.getAskunit();
        String recordunit = rdv.getRecordunit();
        String fileString = rdv.getFileString();
        try {
            path = recordDetailedService.printDetailed(detailedId, suspectId, watermark, number, askunit, recordunit,
                    fileString, rdv.getWantWatermark());
            log.info("下载成功,路径为:{}", JSONObject.toJSONString(path));
            data.put("value", ConstantUtil.PDF_PATH + path);
            result.setCode(200);
            result.setMsg("下载成功！");
            result.setData(data);
            return result;
        } catch (Exception e) {
            log.info("下载pdf文件失败:{}", e);
            data.put("value", e);
            result.setCode(-1);
            result.setMsg("下载失败！");
            result.setData(data);
            return result;
        }
    }

    /**
     * 下载打印笔录内容
     *
     * @param request
     * @param response
     * @param path     下载路径
     */
    @MyPower(name = "下载打印笔录内容", url = "/download", isPublic = true)
    @RequestMapping(value = "/download")
    public void downloadConsole(HttpServletRequest request, HttpServletResponse response, String path) {
        // path = path.replaceAll("\\\\", "/");
        // 获取文件的路径
        if (StringUtil.isEmpty(path)) {
            return;
        }
        if (path.startsWith(ConstantUtil.returnIp())) {
            path = path.substring(ConstantUtil.returnIp().length());
        }
        File file = new File(path);
        if (file.exists()) {
            String fileName = file.getName();
            String fileType = path.substring(path.lastIndexOf("."), path.length());
            log.info("要下载的文件类型为：" + fileType);
            // 通知客服文件的MIME类型
            // if (fileType.equals(".pdf")) {
            response.setContentType("application/pdf;charset=UTF-8");
            // } else if (fileType.equals(".mp3") || fileType.equals(".MP3")) {
            // response.setContentType("audio/mp3;charset=UTF-8");
            // } else if (fileType.equals(".mp4") || fileType.equals(".MP4")) {
            // response.setContentType("video/mpeg4;charset=UTF-8");
            // }
            try {
                // 解决IE和火狐浏览器不兼容，文件名有中文就乱码的问题
                fileName = URLEncoder.encode(fileName, "UTF-8");
                // 设置要下载的文件的名称
                response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                // File file = new File("/data/abcd.pdf");
                FileInputStream input = new FileInputStream(file);
                OutputStream out = response.getOutputStream();
                byte[] b = new byte[2048];
                int len;
                while ((len = input.read(b)) != -1) {
                    out.write(b, 0, len);
                }
                input.close();
                out.close();
                out.flush();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    /**
     * 根据用户id查询自定义笔录模板信息
     *
     * @param policeId 警员id
     * @return
     */
    @ResponseBody
    @MyPower(name = "根据用户id查询自定义笔录模板信息", url = "/findMyModelById")
    @RequestMapping(value = "/findMyModelById")
    public AppResult findMyModelById(String policeId) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        log.info("..........findMyModelById");
        List<RecordCommonalityModel> list = recordCommonalityModelService.findMyModelById(policeId);
        log.info("list:{}", JSONObject.toJSONString(list));
        data.put("value", list);
        result.setCode(200);
        result.setMsg("查询成功！");
        result.setData(data);
        return result;
    }

    /**
     * 添加用户自定义笔录模板信息
     *
     * @param rcm userid 用户id modeltypeid 笔录类型id modelname 笔录类型名称
     * @return
     */
    @ResponseBody
    @MyPower(name = "添加用户自定义笔录模板信息", url = "/addMyModel")
    @RequestMapping(value = "/addMyModel")
    public AppResult addMyModel(@RequestBody RecordCommonalityModel rcm) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        log.info("..........addMyModel");
        rcm.setId(StringUtil.generatorUUID());
        int i = recordCommonalityModelService.addMyModel(rcm);
        log.info("RecordCommonalityModel:{}", JSONObject.toJSONString(rcm));
        if (i == -1) {
            data.put("value", rcm.getId());
            result.setCode(-1);
            result.setMsg("添加失败！");
            result.setData(data);
            return result;
        }
        data.put("value", rcm.getId());
        result.setCode(200);
        result.setMsg("添加成功！");
        result.setData(data);
        return result;
    }

    /**
     * 添加用户自定义笔录模板信息(问与答)
     *
     * @param modelId 模板id
     * @param context 内容
     * @return
     */
    @ResponseBody
    @MyPower(name = "添加用户自定义笔录模板信息(问与答)", url = "/addMyModelQuestionAndAnswer")
    @RequestMapping(value = "/addMyModelQuestionAndAnswer")
///	public AppResult addMyModelQuestionAndAnswer(String modelId, String context) {
    public AppResult addMyModelQuestionAndAnswer(@RequestBody RecordQuestionAndAnswerVo rqa) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        log.info("..........addMyModelQuestionAndAnswer");
        int i = recordQuestionService.addMyModelQuestionAndAnswer(rqa.getModelId(), rqa.getContext());
        if (i == -1) {
            data.put("value", -1);
            result.setCode(-1);
            result.setMsg("添加失败！（可能原因：没有编辑的内容）");
            result.setData(data);
            return result;
        }
        data.put("value", 1);
        result.setCode(200);
        result.setMsg("添加成功！");
        result.setData(data);
        return result;
    }

    /**
     * 编辑用户自定义笔录模板信息(问与答)
     *
     * @param modelId 模板id
     * @param context 内容
     * @return
     */
    @ResponseBody
    @MyPower(name = "编辑用户自定义笔录模板信息(问与答)", url = "/updMyModelQuestionAndAnswer")
    @RequestMapping(value = "/updMyModelQuestionAndAnswer")
///	public AppResult updMyModelQuestionAndAnswer(String modelId, String context) {
    public AppResult updMyModelQuestionAndAnswer(@RequestBody RecordQuestionAndAnswerVo rqa) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        log.info("..........updMyModelQuestionAndAnswer");
        int i = recordQuestionService.updMyModelQuestionAndAnswer(rqa.getModelId(), rqa.getContext(),
                rqa.getPoliceId());
        if (i == -1) {
            data.put("value", -1);
            result.setCode(-1);
            result.setMsg("保存失败！（可能原因：没有编辑的内容）");
            result.setData(data);
            return result;
        } else if (i == -2) {
            data.put("value", i);
            result.setCode(-1);
            result.setMsg("编辑笔录模板信息失败！（只能编辑自己定义的模板）");
            result.setData(data);
        } else {
            data.put("value", 1);
            result.setCode(200);
            result.setMsg("保存成功！");
            result.setData(data);
        }
        return result;
    }

    /**
     * 模糊查询笔录模板(1.笔录类型2.模板来源3.关键字)
     *
     * @param modelId   模板类型id
     * @param modelName 模板名称
     * @param keyWord   笔录内容关键字
     * @param policeId  警员id
     * @return
     */
    @ResponseBody
    @MyPower(name = "模糊查询笔录模板(1.笔录类型2.名称3.关键字)", url = "/findRecordByAll", isPublic = true)
    @RequestMapping(value = "/findRecordByAll")
    public AppResult findRecordByAll(@RequestParam(name = "modelId", required = false) String modelId,
                                     @RequestParam(name = "modelName", required = false) String modelName,
                                     @RequestParam(name = "keyWord", required = false) String keyWord,
                                     @RequestParam(name = "policeId", required = false) String policeId) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        List<RecordCommonalityModel> rcm = recordQuestionService.findRecordByAll(modelId, modelName, keyWord, policeId);
        data.put("value", rcm);
        result.setCode(200);
        result.setMsg("查询成功！");
        result.setData(data);
        return result;
    }

    /**
     * 删除用户自定义笔录模板信息
     *
     * @param userid 用户id
     * @param id     笔录模板id
     * @return
     */
    @ResponseBody
    @MyPower(name = "删除用户自定义笔录模板信息", url = "/deleteMyModel", isPublic = true)
    @RequestMapping(value = "/deleteMyModel")
    public AppResult deleteMyModel(@RequestBody RecordCommonalityModel rcm) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        int i = recordCommonalityModelService.deleteMyModel(rcm);
        if (i == -1) {
            data.put("value", rcm.getId());
            result.setCode(-1);
            result.setMsg("删除用户自定义笔录模板信息失败！");
            result.setData(data);
        } else if (i == -2) {
            data.put("value", rcm.getId());
            result.setCode(-1);
            result.setMsg("删除笔录模板信息失败！（只能删除自己自定义的模板）");
            result.setData(data);
        } else {
            data.put("value", rcm.getId());
            result.setCode(200);
            result.setMsg("删除用户自定义笔录模板信息成功！");
            result.setData(data);
        }
        return result;
    }

    /**
     * 打印列表中的笔录内容
     *
     * @param response
     * @param detailedId 笔录id
     * @param suspectId  嫌疑人id
     * @param watermark  水印内容
     * @return
     */
    @ResponseBody
    @MyPower(name = "打印列表中的笔录内容", url = "/printListDetailed")
    @RequestMapping(value = "/printListDetailed")
    public AppResult printListDetailed(HttpServletResponse response, @RequestBody RecordDetailedVo rdv) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        // 生成pdf文件的路径
        String path = null;
        try {
            path = recordDetailedService.printListDetailed(rdv.getDetailedId(), rdv.getSuspectId(), rdv.getWatermark(), rdv.getFileString());
            log.info("下载成功,路径为:{}", JSONObject.toJSONString(path));
            data.put("value", path);
            result.setCode(200);
            result.setMsg("下载成功！");
            result.setData(data);
            return result;
        } catch (Exception e) {
            log.info("下载pdf文件失败:{}", e);
            data.put("value", e);
            result.setCode(-1);
            result.setMsg("下载失败！");
            result.setData(data);
            return result;
        }
    }

    /**
     * 查询笔录申请
     *
     * @param recordApplyParams
     * @return
     */
    @ResponseBody
    @MyPower(name = "查询笔录申请", url = "/findRecordApply", isPublic = true)
    @RequestMapping(value = "/findRecordApply")
    public AppResult findRecordApply(@RequestBody @Validated({First.class}) RecordApplyParams recordApplyParams) {
        JSONObject data = new JSONObject();
        data.put("value", recordApplyService.findRecordApply(recordApplyParams));
        return AppResult.builder().setCode(ResultEnum.SUCCESS.getCode()).setMsg("查询笔录申请列表成功！").setData(data);
    }

    /**
     * 提交查看笔录申请
     *
     * @param recordApply
     * @return
     */
    @ResponseBody
    @MyPower(name = "提交查看笔录申请", url = "/addRecordApply", isPublic = true)
    @RequestMapping(value = "/addRecordApply")
    public AppResult addRecordApply(@RequestBody @Validated({Two.class}) RecordApply recordApply) {
        if (recordApplyService.addRecordApply(recordApply) > 0) {
            return AppResult.builder().setCode(ResultEnum.SUCCESS.getCode()).setMsg("提交查看笔录申请成功！");
        } else {
            return AppResult.builder().setCode(ResultEnum.FAIL.getCode()).setMsg("提交查看笔录申请失败！");
        }
    }

    /**
     * 同意/拒绝查看笔录申请
     *
     * @param recordApply
     * @return
     */
    @ResponseBody
    @MyPower(name = "同意/拒绝查看笔录申请", url = "/updateRecordApply", isPublic = true)
    @RequestMapping(value = "/updateRecordApply")
    public AppResult updateRecordApply(@RequestBody @Validated({First.class}) RecordApply recordApply) {
        if (recordApplyService.updateRecordApply(recordApply) > 0) {
            return AppResult.builder().setCode(ResultEnum.SUCCESS.getCode()).setMsg("处理笔录申请成功！");
        } else {
            return AppResult.builder().setCode(ResultEnum.FAIL.getCode()).setMsg("处理笔录申请失败！");
        }
    }

    /**
     * 查看笔录文件
     *
     * @param id       笔录申请id
     * @param policeId 当前民警id
     * @return
     */
    @ResponseBody
    @MyPower(name = "查看笔录文件", url = "/findPassRecord", isPublic = true)
    @RequestMapping(value = "/findPassRecord")
    public AppResult findPassRecord(@NotNull(message = "传入的id为null，请传值")
                                    @NotEmpty(message = "传入的id空字符串，请传值") String id,
                                    @NotNull(message = "传入的policeId为null，请传值")
                                    @NotEmpty(message = "传入的policeId空字符串，请传值") String policeId) {
        JSONObject data = new JSONObject();
        String path = recordApplyService.findPassRecord(id, policeId);
        data.put("value", path);
        if (StringUtil.isEmpty(path)) {
            return AppResult.builder().setCode(ResultEnum.FAIL.getCode()).setMsg("查看笔录文件失败！可能原因：1.笔录文件不存在；2.已过查看期限；").setData(data);
        } else {
            return AppResult.builder().setCode(ResultEnum.SUCCESS.getCode()).setMsg("查看笔录文件成功！").setData(data);
        }
    }

    /**
     * 查询我的笔录（今天、昨天、上周、更早）
     *
     * @param recordApplyParams
     * @return
     */
    @ResponseBody
    @MyPower(name = "查询我的笔录（今天、昨天、上周、更早）", url = "/findMyRecordGroupDate", isPublic = true)
    @RequestMapping(value = "/findMyRecordGroupDate")
    public AppResult findMyRecordGroupDate(@RequestBody @Validated({First.class}) RecordApplyParams recordApplyParams) {
        JSONObject data = new JSONObject();
        data.put("value", recordApplyService.findMyRecordGroupDate(recordApplyParams));
        return AppResult.builder().setCode(ResultEnum.SUCCESS.getCode()).setMsg("查询我的笔录（今天、昨天、上周、更早）成功！").setData(data);
    }

    /**
     * 查询我的笔录
     *
     * @param recordApplyParams
     * @return
     */
    @ResponseBody
    @MyPower(name = "查询我的笔录", url = "/findMyRecord", isPublic = true)
    @RequestMapping(value = "/findMyRecord")
    public AppResult findMyRecord(@RequestBody @Validated({First.class}) RecordApplyParams recordApplyParams) {
        JSONObject data = new JSONObject();
        data.put("value", recordApplyService.findMyRecord(recordApplyParams));
        return AppResult.builder().setCode(ResultEnum.SUCCESS.getCode()).setMsg("查询我的笔录成功！").setData(data);
    }

    /**
     * 笔录搜索
     *
     * @param recordApplyParams
     * @return
     */
    @ResponseBody
    @MyPower(name = "笔录搜索", url = "/findRecord", isPublic = true)
    @RequestMapping(value = "/findRecord")
    public AppResult findRecord(@RequestBody @Validated({Two.class}) RecordApplyParams recordApplyParams) {
        JSONObject data = new JSONObject();
        data.put("value", recordApplyService.findRecord(recordApplyParams));
        return AppResult.builder().setCode(ResultEnum.SUCCESS.getCode()).setMsg("笔录搜索成功！").setData(data);
    }


}
